<?php

class CExpressCompany extends Zend_Db_Table{
	
	protected $_name;
	
	protected $_primary;

	
	public function _setup(){
		
		$this->_name="express_companies";
		
		$this->_primary="companyid";
		
		parent::_setup();
		
	}
	
	public function createCompany($data){
		
		$companyid=$this->insert($data);

		return $companyid;
		
	}
	
	public function editCompany($companyid,$data){
		
		$db=$this->getAdapter();
		
		$where = $db->quoteInto('companyid = ?', $companyid);

		$rows_affected=$db->update($this->_name,$data,$where);
		
		if($rows_affected!=1){
			
			return false;
			
		}else{
			
			return true;
			
		}
		
	}
	

	
	public function getDetail($companyid){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where($this->_name.'.companyid = ? ',$companyid);
		
		return $db->fetchAll($select);
		
	}
	
	public function delCompanies($companyidArray){
		
		$db=$this->getAdapter();
		
		$companyidString=join(',',$companyidArray);
		
		$result=$db->query("DELETE FROM $this->_name WHERE companyid IN ($companyidString)");
		
		return $result;
		
	}
	
	
	
	public function getAllCompanyCounts($where=''){
		
		$db=$this->getAdapter();
		
		$select = $db->select();

		$select->from($this->_name,'*');
		
		if($where!=''){
			
			$select->where($where);
	
		}
		
		return $db->fetchOne($select);
		
	}
	
	public function getAllCompanies($from,$counts,$where=''){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		if($where!=''){
			
			$select->where($where);
			
		}
		
		$select->order("$this->_name.add_time DESC");
		
		if($counts!=0){
		
			$select->limit($counts, $from);
		
		}
		
		return $db->fetchAll($select);
		
	}
	

	
}